<?php

namespace App\Util;

class FileWriter
{
    private $file;

    private $mode = 'w+';

    private $data = null;

    public function __construct($file, $data = null, $mode = 'w+')
    {
        $this->file = $file;
        $this->dir = dirname($file);
        $this->data = $data;
        $this->mode = $mode;
    }

    public function write()
    {
        $handler = fopen($this->file, $this->mode);
        $ok = fwrite($handler, $this->data);
        $ok = $ok && fclose($handler);
        return $ok;
    }

    public function save()
    {
        return $this->write();
    }
}